package com.kma.summer2012.server;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.kma.summer2012.client.UserService;
import com.kma.summer2012.factory.DAOFactory;
import com.kma.summer2012.factory.SpringBeansFactory;
import com.kma.summer2012.model.User;
import com.kma.summer2012.server.proxy.UserProxy;
import com.kma.summer2012.shared.model.UIUser;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

public class UserServiceImpl extends RemoteServiceServlet implements UserService {


    public UIUser getUserById(BigInteger id) {
        DAOFactory factory = (DAOFactory) SpringBeansFactory.getInstance().getBeanByName("daoFactory");
        return UserProxy.createFromUser(factory.getUserDAO().getUserById(id));
    }

    public List<UIUser> getUserAllUsers() {
        List<UIUser> uiUsers = new ArrayList<UIUser>();
        DAOFactory factory = (DAOFactory) SpringBeansFactory.getInstance().getBeanByName("daoFactory");
        for (User user : factory.getUserDAO().getAllUsers()) {
            uiUsers.add(UserProxy.createFromUser(user));
        }
        return uiUsers;
    }

}